package org.lanqiao.tjut.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.tjut.bean.TBStudentBean;
import org.lanqiao.tjut.model.ModelFactory;
import org.lanqiao.tjut.myUtils.MyUtils;

import com.alibaba.fastjson.JSON;

/**
 * Servlet implementation class StudentInfoAjaxDeleteQueryServlet
 */
@WebServlet("/StudentInfoAjaxDeleteServlet")
public class StudentInfoAjaxDeleteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 获取删除记录的id
		String delIndex=request.getParameter("delIndex");
		//如果删除记录不为null，则进行删除操作
		if(delIndex!=null&&!delIndex.equals("")){
			//删除操作
			ModelFactory.getStudentInfoModelInstance().deleteStudentInfoById(delIndex);
		}
		//无论成功与否，都要再进行ajax查询处理
		TBStudentBean stuB=MyUtils.convertRequest2Bean(request,TBStudentBean.class, null, null);
        List<TBStudentBean> lstStus=ModelFactory.getStudentInfoModelInstance().queryStudentInfoByParas(stuB);
        String json=JSON.toJSONStringWithDateFormat(lstStus, "yyyy-MM-dd HH:mm:ss");
        PrintWriter pw=response.getWriter();
        pw.write(json);
        pw.flush();
        pw.close();
	}

}
